# Separate imputes to calculate statistics in each.
# Include sample weights, age, race, income, assets

scf89_22 <- vector(mode="list",length = 12)
s <- 0
for (year in unique(SCF89_22$YEAR)){
  s <- s + 1
  index <- which(SCF89_22$YEAR == year)
  N <- length(index)/5
  Y <- cbind(SCF89_22$WGT[index],    #1
             SCF89_22$AGE[index],   #2
             SCF89_22$RACE[index],   #3
             SCF89_22$INCOME[index], #4
             SCF89_22$ASSET[index]  #5
  )
  imps <- vector(mode="list",length = 5)
  imp1 <- seq(from = 1, to = length(index), by = 5)
  imp2 <- seq(from = 2, to = length(index), by = 5)
  imp3 <- seq(from = 3, to = length(index), by = 5)
  imp4 <- seq(from = 4, to = length(index), by = 5)
  imp5 <- seq(from = 5, to = length(index), by = 5)
  
  imps[[1]] <- Y[imp1,]
  imps[[2]] <- Y[imp2,]
  imps[[3]] <- Y[imp3,]
  imps[[4]] <- Y[imp4,]
  imps[[5]] <- Y[imp5,]
  
  scf89_22[[s]] <- imps
}

names(scf89_22) <- as.character(seq(from = 1989,to = 2022, by = 3))

rm(imps,imp1,imp2,imp3,imp4,imp5,Y,index,SCF89_22,N,s,vars,y,year,years)

